/*
 * @Author: lilongbiao guildwars@qq.com
 * @Date: 2024-03-31 02:01:18
 * @LastEditors: lilongbiao guildwars@qq.com
 * @LastEditTime: 2024-04-07 01:12:56
 * @FilePath: \work-vscode\vue3demo\demo\src\api\login.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { $post } from "../utils/request";
import {$setToken} from "../utils/request";
import { md5 } from "js-md5";
//因为和后台返回的message同名，所以这里改名为messager
import { message as messager } from "ant-design-vue";


export const $login = async (params) => {
  console.log("params.password:" + params.password);
  //   params.password = md5(params.password);
  console.log("params.password:" + params.password);
  let data = await $post("sys/logintest", params);
  console.log("data:" + data);
  let { success, message, code } = data;
  console.log("success:" + success);
  console.log("code:" + code);
  console.log("message:" + message);
  if (success) {
    let {token} =data.result;
    console.log("result.token:"+token);
    sessionStorage.setItem('token',token);
    $setToken(token);
    messager.success('登录成功');
  }else{
    messager.error('登陆失败:'+message);
  }
  return success;
};
